<include file="Common/header-control" />
<div class="row">
    <div class="col-md-12">
        <ul class="nav nav-tabs">
            <li><a href="{:U('control/user/list')}">用户</a></li>
            <if condition="!empty($user)">
                <li class="active"><a href="{:U('control/user/modify?uid=' . $user['uid'])}">编辑用户</a></li>
                <li><a href="{:U('control/user/create')}">新增用户</a></li>
            <else/>
                <li class="active"><a href="{:U('control/user/create')}">新增用户</a></li>
            </if>
        </ul>
    </div>
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <if condition="!empty($user)">
                    <h2><i class="fa fa-edit"></i> 编辑用户资料</h2>
                <else/>
                    <h2><i class="fa fa-edit"></i> 新增用户</h2>
                </if>
            </div>
            <div class="box-content">
                <script>
                    require(['jquery', 'util'], function($, u){
                        $('#theform').submit(function(){
                            if($.trim($('input[name="username"]').val()) == '') {
                                u.message('必须输入用户名');
                                return false;
                            }
                            <if condition="empty($user)">
                                if($('input[name="password"]').val() == '') {
                                    u.message('必须输入密码');
                                    return false;
                                }
                            </if>
                            if($('select[name="role"]').val() == '') {
                                u.message('必须选择所属用户组');
                                return false;
                            }
                        });
                    });
                </script>
                <form id="theform" action="" method="post" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-4">
                            <if condition="!empty($user)">
                                <input class="form-control" type="text" disabled value="{$user['username']}" />
                                <input name="username" type="hidden"  value="{$user['username']}"/>
                            <else/>
                                <input class="form-control" type="text" name="username" value="{$user['username']}" />
                            </if>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-4">
                            <input class="form-control" type="text" name="password" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">所属用户组</label>
                        <div class="col-sm-3">
                            <select class="form-control" name="role">
                                <option value="">请选择用户组</option>
                                <foreach name="roles" item="role">
                                    <option value="{$role['id']}"<if condition="$role['id'] == $user['role']"> selected="selected"</if> >{$role['title']}</option>
                                </foreach>
                            </select>
                        </div>
                        <div class="col-sm-1">
                            <p class="form-control-static">
                                <a href="{:U('control/acl/roles')}">编辑用户组</a>
                            </p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">用户状态</label>
                        <div class="col-sm-4">
                            <label class="radio-inline">
                                <input type="radio" name="status" value="0"<if condition="empty($user) || $user['status'] == '0'"> checked</if>> 启用
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="status" value="-1"<if condition="$user['status'] == '-1'"> checked</if>> 禁用
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-1">
                            <if condition="!empty($user)">
                                <button type="submit" class="btn btn-block btn-primary">保存</button>
                            <else/>
                                <button type="submit" class="btn btn-block btn-primary">新增</button>
                            </if>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<include file="Common/footer-control" />
